<template>
  <ms-dialog :title="title" :dialog-visible="dialogVisible" @show="showDialog" @ok="handleSaveForm" @close="handleCloseDialog">
    <el-form v-loading="loading" label-width="80px" ref="formValid" :rules="rules" :model="form">
      <el-form-item label="部门名称" prop="name">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="上级部门" prop="pid">
        <dep-tree v-model="form.pid" />
      </el-form-item>
      <el-form-item label="部门状态" prop="status">
        <el-switch v-model="form.status" />
      </el-form-item>
    </el-form>
  </ms-dialog>
</template>

<script>
import MsDialog from '@/common/dialog'
import { DepTree } from '@/common/service'
import tip from '@/mixins/tip'
const preFixUrl = '/sys/department/'
export default {
  components: {
    MsDialog,
    DepTree
  },
  mixins: [tip],
  data() {
    return {
      apiUrl: {
        get: `${preFixUrl}getById`,
        save: `${preFixUrl}save`
      },
      rules: {
        pid: [
          { required: true, message: '请输入上级部门', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请输入部门名称', trigger: 'blur' }
        ]
      }
    }
  }
}
</script>
